{include file="header" /}

<link rel="stylesheet" href="__CSS__sign/public.css" />
<link rel="stylesheet" href="__CSS__sign/signin.css" />
<link rel="stylesheet" href="__CSS__pay/common.css" />
<link href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.css" rel="stylesheet">
<body>
<div class="top flex flex-align-end flex-pack-center flex-warp">
    <div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
        <div class="out-2 flex flex-align-center flex-pack-center">
            <div class="signBtn">
                <strong id="sign-txt">打卡</strong>
                <span>已打卡<text id="sign-count">0</text>天</span>
            </div>
        </div>
    </div>
</div>
<div class="tips"></div>
<div class="Calendar">
    <div id="toyear" class="flex flex-pack-center">
        <div id="idCalendarPre">&lt;</div>
        <div class="year-month">
            <span id="idCalendarYear">2018</span>年<span id="idCalendarMonth">6</span>月
        </div>
        <div id="idCalendarNext">&gt;</div>
    </div>
    <table border="1px" cellpadding="0" cellspacing="0">
        <thead>
        <tr class="tou">
            <td>日</td>
            <td>一</td>
            <td>二</td>
            <td>三</td>
            <td>四</td>
            <td>五</td>
            <td>六</td>
        </tr>
        </thead>
        <tbody id="idCalendar">
        </tbody>
    </table>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
<script type="text/javascript" src="__JS__sign/rili.js"></script>
<script language="JavaScript">
    var isSign = false;

    //获取打卡记录
    var datas = {
        interface:'users@getSignData',
    };
    common.ajax({
        data: datas,
        success: function (res) {
            if (res.status == '2000') {
                    c(res.result.my_day,res.result.q_day,res.result.w_day);
            } else if (res.status == '5000') {
                falert(data.msg);
            }
        }
    });

    function c(myday,q_day,w_day){
        var cale = new Calendar("idCalendar", {
            qdDay: myday,
            q_day: q_day,
            w_day: w_day,
            onToday: function(o) {
                o.className = "onToday";
            },
            onSignIn: function (){
                $$("sign-txt").innerHTML = '已打卡';
            },
            onFinish: function() {
                $$("sign-count").innerHTML = myday.length//已打卡次数
                $$("idCalendarYear").innerHTML = this.Year;
                $$("idCalendarMonth").innerHTML = this.Month; //表头年份

            }
        });
        $$("idCalendarPre").onclick = function() {
            cale.PreMonth();
        }
        $$("idCalendarNext").onclick = function() {
            cale.NextMonth();
        }
        //添加今天签到
        $$("signIn").onclick = function() {
            if(isSign == false) {
                var res = cale.SignIn();
                if(res == '2') {
                    $$("sign-txt").innerHTML = '已打卡';
                    $.alert('点击缺卡日期可进行补卡')
                } else{
                    btn_Submit(res,'打卡成功');
                }
            } else {
                $.alert('点击缺卡日期可进行补卡')
            }

        }
    }

    //保存打卡记录
    function btn_Submit(sign_time,msg) {
        var datas = {
            interface:'users@sign',
            sign_time: sign_time,
        };
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    $$("sign-txt").innerHTML = '已打卡';
                    $$("sign-count").innerHTML = parseInt($$("sign-count").innerHTML) + 1;
                    isSign = true;
                    $.alert(msg,function () {
                        location.reload();
                    })
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });

    }

    //补卡
    function patch_card(y,m,d) {
        var date = new Date(y+'-'+m+'-'+d);
        btn_Submit(date.getTime()/1000,'补卡成功');
    }
</script>

</body>

{include file="footer" /}